package com.itheima.web;

import com.itheima.dto.RoleDto;
import com.itheima.pojo.Role;
import com.itheima.service.RoleService;
import com.itheima.service.RoleUserService;
import com.itheima.support.PageResult;
import com.itheima.support.QueryPageBean;
import com.itheima.support.Result;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author admin
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @DubboReference
    private RoleService roleService;

    @DubboReference
    private RoleUserService roleUserService;

    @GetMapping("/findAllRole")
    public Result<List<Role>> findAllRole(){
        return Result.build(roleService.list());
    }

    @PostMapping("/findAllRoleByPage")
    public PageResult findAllRoleByPage(@RequestBody QueryPageBean queryPageBean){
        return roleService.findAllRoleByPage(queryPageBean);
    }

    @PostMapping("/saveOrUpdateRole")
    public Result<Boolean> saveOrUpdateRole(@RequestBody Role role){
        return Result.build(roleService.saveOrUpdate(role));
    }

    @GetMapping("/deleteRoleById/{id}")
    public Result<Boolean> deleteRoleById(@PathVariable("id") Long id){
            return Result.build(roleService.deleteRoleById(id));
    }

    @PostMapping("/roleUserSave")
    public Result<Boolean> roleUserSave(@RequestBody RoleDto roleDto){
        return Result.build(roleUserService.saveByUserIds(roleDto));
    }
}
